<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>解决高度塌陷和外边距问题</title>
  </head>
  <body>
        <div class="box1 clearfix">
            <div class="box2"></div>
        </div>
  </body>
<style>
    *{
        margin: 0;
        padding: 0;
    }
    .box1{
        width: 200px;
        height: 200px;
        background-color: #bfa;
    }
    /*.box1::before{
        content: '';
        display: table;
    }*/
    .box2{
        width: 100px;
        height: 100px;
        background-color: orange;
        margin-top: 100px;
    }
    /*处理高度塌陷和外边距问题 增加cleafix类名即可*/
    .clearfix::after,
    .clearfix::before{
        content: '';
        display: table;
        clear: both;
    }


</style>
</html>
